/**
 * @file    hal_config.h
 * @author  Azolla (1228449928@qq.com)
 * @brief   config hal param.
 * @version 0.1
 * @date    2022-11-03
 * 
 * @copyright Copyright (c) 2022
 * */
#ifndef __HAL_CONFIG_H__
#define __HAL_CONFIG_H__

#include "stdio.h"
#include "string.h"

#include "sdkconfig.h"

/************************************* Device Config ****************************************/  
/************************************* Device Config ****************************************/  
/**< device product id. */
#define ROOT_PID            0x00    // 网关
#define BED_PID             0x01    // 智能床
#define LIGHT_PID           0x02    // 灯光
#define SWITCH_PID          0x03    // 开关
#define CURTION_PID         0x04    // 窗帘
#define SUMANBO_PID         0x05    // 舒曼波
#define TUMBLE_PID          0x06    // 跌倒
#define SMR_PID             0x07    // Sleep monitoring radar 睡眠监测雷达
#define CHAIR_MSAGE_PID     0x08    // 按摩椅
#define CHAIR_SMART_PID     0x09    // 智能椅
#define DESK_SMART_PID      0x0A    // 智能桌/升降桌
#define CONFIG_DEV_PID      ROOT_PID   
/*******************************************************************************************/ 


/************************************* IO Config ****************************************/ 
// UART1 PIN Config...
#define CONFIG_GPIO_UART1_RXD           (25)
#define CONFIG_GPIO_UART1_TXD           (26)
#define CONFIG_GPIO_UART1_RTS           (27)
 
// ===============================================================================
#define CONFIG_GPIO_AUDIO_TXD           (37)
#define CONFIG_GPIO_AUDIO_RXD           (36)
 
#define CONFIG_GPIO_KEY                 (38)
//====================================================================================

/*************************************************************************************
                                    switchs
**************************************************************************************/ 

#ifndef __SWITCSH_H__
#define __SWITCSH_H__
#include <string.h>
#include <regex.h>
#include <stdbool.h>

/** Begin a switch for the string x */
#define switchs(x) \
    { char *__sw = (x); bool __done = false; bool __cont = false; \
        regex_t __regex; regcomp(&__regex, ".*", 0); do {

/** Check if the string matches the cases argument (case sensitive) */
#define cases(x)    } if ( __cont || !strcmp ( __sw, x ) ) \
                        { __done = true; __cont = true;

/** Check if the string matches the icases argument (case insensitive) */
#define icases(x)    } if ( __cont || !strcasecmp ( __sw, x ) ) { \
                        __done = true; __cont = true;

/** Check if the string matches the specified regular expression using regcomp(3) */
#define cases_re(x, flags) }  regfree ( &__regex ); if ( __cont || ( \
                              0 == regcomp ( &__regex, x, flags ) && \
                              0 == regexec ( &__regex, __sw, 0, NULL, 0 ) ) ) { \
                                __done = true; __cont = true;

/** Default behaviour */
#define defaults    } if ( !__done || __cont ) {

/** Close the switchs */
#define switchs_end } while ( 0 ); regfree(&__regex); }

#endif // __SWITCHS_H__

#if 0 // Tset
switchs(argv[1]) {
    cases("foo")
    cases("bar")
        printf("foo or bar (case sensitive)\n");
        break;

    icases("pi")
        printf("pi or Pi or pI or PI (case insensitive)\n");
        break;

    cases_re("^D.*",0)
        printf("Something that start with D (case sensitive)\n");
        break;

    cases_re("^E.*",REG_ICASE)
        printf("Something that start with E (case insensitive)\n");
        break;

    cases("1")
        printf("1\n");
        // break omitted on purpose

    cases("2")
        printf("2 (or 1)\n");
        break;

    defaults
        printf("No match\n");
        break;
} switchs_end;
#endif
 

#endif  /*__HAL_CONFIG_H__ END.*/